package com.example.kotlin.utils

import java.util.*

object GenerateString {
    //length用户要求产生字符串的长度
    fun getRandomString(length: Int): String {
        val str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
        val random = Random()
        val sb = StringBuffer()
        for (i in 0 until length) {
            val number = random.nextInt(62)
            sb.append(str[number])
        }
        return sb.toString()
    }

    fun convertArrayToString(strArr: Array<String>?): String {
        if (strArr == null || strArr.size == 0) {
            return ""
        }
        var res = ""
        var i = 0
        val len = strArr.size
        while (i < len) {
            res += strArr[i]
            if (i < len - 1) {
                res += ","
            }
            i++
        }
        return res
    }
}